package com.mz.ozy.mvp.model;

import android.content.Context;

import com.mz.ozy.constants.Constants;
import com.mz.ozy.net.RetrofitUtils;
import com.mz.ozy.utils.JsonUtils;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.Observable;
import okhttp3.ResponseBody;

/**
 * Created by administrator on 2018/12/3.
 */
public class AddressModel {

    public Observable<ResponseBody> onList(Context context) {
        Map<String, String> maps = new HashMap<>();
        return RetrofitUtils.getApiService(context).post(Constants.TransCode.TransCode10029, JsonUtils.requestJsonDate(maps), Constants.tokenId);
    }

    /**
     * 收货地址新增
     *
     * @param context
     * @param shuname   姓名
     * @param shmobile  电话
     * @param shaddr    详细地址
     * @param area0id   省份ID
     * @param area1id   市ID
     * @param area2id   区ID
     * @param isdefault 是否默认地址，0-否；1-是
     * @return
     */
    public Observable<ResponseBody> onAdd(Context context, String shuname, String shmobile,
                                          String shaddr, String area0id, String area1id, String area2id, String isdefault) {
        Map<String, String> maps = new HashMap<>();
        maps.put("consignee", shuname);
        maps.put("contactnumber", shmobile);
        maps.put("xxaddress", shaddr);
        maps.put("area0id", area0id);
        maps.put("area1id", area1id);
        maps.put("area2id", area2id);
        maps.put("isdefault", isdefault);
        return RetrofitUtils.getApiService(context).post(Constants.TransCode.TransCode10025, JsonUtils.requestJsonDate(maps), Constants.tokenId);
    }


    /**
     * 收货地址修改
     *
     * @param context
     * @param aid       收货地址ID
     * @param shuname   姓名
     * @param shmobile  电话
     * @param shaddr    详细地址
     * @param area0id   省份ID
     * @param area1id   市ID
     * @param area2id   区ID
     * @return
     */
    public Observable<ResponseBody> onUpdate(Context context, String aid, String shuname, String shmobile,
                                             String shaddr, String area0id, String area1id, String area2id) {
        Map<String, String> maps = new HashMap<>();
        maps.put("id", aid);
        maps.put("consignee", shuname);
        maps.put("contactnumber", shmobile);
        maps.put("xxaddress", shaddr);
        maps.put("area0id", area0id);
        maps.put("area1id", area1id);
        maps.put("area2id", area2id);
        return RetrofitUtils.getApiService(context).post(Constants.TransCode.TransCode10027, JsonUtils.requestJsonDate(maps), Constants.tokenId);
    }

    /**
     * 默认收货地址
     *
     * @return
     */
    public Observable<ResponseBody> onDefault(Context context, String aid) {
        Map<String, String> maps = new HashMap<>();
        maps.put("id", aid);
        return RetrofitUtils.getApiService(context).post(Constants.TransCode.TransCode10026, JsonUtils.requestJsonDate(maps), Constants.tokenId);
    }


    /**
     * 删除
     *
     * @param context
     * @param aid     收货地址ID
     * @return
     */
    public Observable<ResponseBody> onDel(Context context, String aid) {
        Map<String, String> maps = new HashMap<>();
        maps.put("id", aid);
        return RetrofitUtils.getApiService(context).post(Constants.TransCode.TransCode10028, JsonUtils.requestJsonDate(maps), Constants.tokenId);
    }


}
